package com.tourManagement.controller;

import com.tourManagement.entity.RT;
import com.tourManagement.entity.行程信息;
import com.tourManagement.service.行程管理Service;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

/**
 * @author xiaoRan
 */
@RestController
@AllArgsConstructor
@RequestMapping("/travel_info")
public class 行程管理Controller {
    private 行程管理Service travelS;

    @GetMapping("/test")
    public String test() {
        return "111";
    }

    @PostMapping("/insert")
    public RT insert(行程信息 data) throws SQLException {
        return RT.success(travelS.insert(data));
    }

    @PostMapping("/delete")
    public RT delete(String id) throws SQLException {
        if (id.isEmpty()) {
            return RT.error("id不能为空");
        }
        return RT.success(travelS.delete(id));
    }

    @PostMapping("/update")
    public RT update(行程信息 data) throws SQLException {
        if (data.getId().isEmpty()) {
            return RT.error("id不能为空");
        }
        return RT.success(travelS.update(data));
    }

    @GetMapping("/selectByRoute")
    public RT selectByRoute(Integer routeId) throws SQLException {
        return RT.success(travelS.selectList(routeId));
    }

    @GetMapping("/selectByDay")
    public RT selectByDay(Integer routeId, Integer day) throws SQLException {
        return RT.success(travelS.selectList(routeId, day));
    }

}
